package com.itheima;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

@SpringBootTest// 如果在测试类中添加了这个注解，那么将来单元测试方法执行之前，会先初始化Spring容器，再执行测试方法
public class RedisTest {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Test
    public void testSet(){
        // 往Redis中存储一个键值对 StringRedisTemplate
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();

        operations.set("name","itcast");
        operations.set("id", "1", 10, TimeUnit.SECONDS);
    }
    @Test
    public void testGet(){
        // 往Redis中获取一个键值对
        ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();

        String name = operations.get("name");
        System.out.println(name);
    }
}
